import 'package:flutter/material.dart';
import 'package:flutter_architecture/config/app_theme.dart';
import 'package:flutter_architecture/constant/drawer_enum.dart';
import 'package:flutter_architecture/views/common/curved_navigation_bar_page.dart';
import 'package:flutter_architecture/views/common/feed_back_page.dart';
import 'package:flutter_architecture/views/common/help_page.dart';
import 'package:flutter_architecture/views/common/invite_friend_page.dart';
import 'package:flutter_architecture/widgets/custom_drawer/drawer_user_controller.dart';
/// 抽屉导航
/// @author: dingwen
/// @date: 2021/1/9

class NavigationDrawerPage extends StatefulWidget {
  @override
  _NavigationDrawerPageState createState() => _NavigationDrawerPageState();
}

class _NavigationDrawerPageState extends State<NavigationDrawerPage> {
  ///显示的页面
  Widget page;
  ///子抽屉类型
  DrawerEnum drawerEnum;

  @override
  void initState() {
    drawerEnum = DrawerEnum.HOME;
    page =  CuredNavigationBarPage();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: AppTheme.nearlyWhite,
      child: SafeArea(
        top: false,
        bottom: false,
        child: Scaffold(
          backgroundColor: AppTheme.nearlyWhite,
          body: DrawerUserController(
            drawerEnum: drawerEnum,
            drawerWidth: MediaQuery.of(context).size.width * 0.75,
            onDrawerCall: (DrawerEnum drawerEnum) {
              changeDrawer(drawerEnum);
              //callback from drawer for replace screen as user need with passing DawerEnum(Enum index)
            },
            page: page,
            //we replace screen view as we need on navigate starting screens like MyHomePage, HelpScreen, FeedbackScreen, etc...
          ),
        ),
      ),
    );
  }

  ///点击抽屉显示到对应的页面
  void changeDrawer(DrawerEnum drawer) {
    //相等就不用替换了
    if (drawerEnum != drawer) {
      drawerEnum = drawer;
      switch(drawerEnum){
        case DrawerEnum.HOME:
          page =  CuredNavigationBarPage();
          break;
        case DrawerEnum.Help:
          page = HelpPage();
          break;
        case DrawerEnum.FeedBack:
          page = FeedbackPage();
          break;
        case DrawerEnum.Invite:
          page = InviteFriendPage();
          break;
      }
    }else{
      page =  CuredNavigationBarPage();
    }
    setState(() {});
  }
}
